package com.nobug.controller;

import com.fasterxml.jackson.databind.ser.Serializers;
import com.nobug.bean.BaseRespVo;
import com.nobug.bean.InfoBean;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("admin/auth/")
public class LoginController {

    @RequestMapping("login")
    public BaseRespVo login(@RequestBody Map map) {
        Object username = map.get("username");
        Object password = map.get("password");
        if("admin123" .equals(username) && "admin123".equals(password)) return BaseRespVo.ok("9ad5d580-7f9e-483c-b687-a2b41f9bdad1");
        else if("mall123" .equals(username) && "mall123".equals(password)) return BaseRespVo.ok("5e17997b-f105-4550-b2e4-4a2d98f38b66");
        else if("promotion123" .equals(username) && "promotion123".equals(password)) return BaseRespVo.ok("9ce0d38d-852b-4ae9-964d-6173a6487a27");
        else return BaseRespVo.fail("用户账号或者密码不正确", 605);
    }

    @RequestMapping("info")
    public BaseRespVo info(String token){
        InfoBean infoBean = new InfoBean();
        if("9ad5d580-7f9e-483c-b687-a2b41f9bdad1".equals(token)) {
            infoBean.setAvatar("https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif");
            infoBean.setName("admin123");
            List<String> roles = new ArrayList<>();
            roles.add("超级管理员");
            List<String> perms = new ArrayList<>();
            perms.add("*");
            infoBean.setRoles(roles);
            infoBean.setPerms(perms);
            return BaseRespVo.ok(infoBean);
        }

        else if (("5e17997b-f105-4550-b2e4-4a2d98f38b66").equals(token)){
            infoBean.setAvatar("https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif");
            infoBean.setName("mall123");
            List<String> roles = new ArrayList<>();
            roles.add("商场管理员");
            List<String> perms = new ArrayList<>();
            perms.add("GET /admin/brand/list");
            perms.add("POST /admin/category/delete");
            perms.add("GET /admin/category/read");
            perms.add("POST /admin/category/create");
            perms.add("POST /admin/brand/delete");
            perms.add("POST /admin/brand/create");
            perms.add("GET /admin/category/list");
            perms.add("POST /admin/category/update");
            perms.add("GET /admin/brand/read");
            perms.add("POST /admin/brand/update");
            infoBean.setRoles(roles);
            infoBean.setPerms(perms);
            return BaseRespVo.ok(infoBean);



        }

        else {
            infoBean.setAvatar("https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif");
            infoBean.setName("promotion123");
            List<String> roles = new ArrayList<>();
            roles.add("推广管理员");
            List<String> perms = new ArrayList<>();
            perms.add("POST /admin/topic/create");
            perms.add("POST /admin/ad/create");
            perms.add("GET /admin/topic/read");
            perms.add("POST /admin/coupon/delete");
            perms.add("GET /admin/ad/read");
            perms.add("GET /admin/coupon/list");
            perms.add("POST /admin/groupon/delete");
            perms.add("GET /admin/groupon/list");
            perms.add("POST /admin/topic/delete");
            perms.add("POST /admin/ad/delete");
            perms.add("POST /admin/groupon/update");
            perms.add("GET  /admin/groupon/listRecord");
            perms.add("POST /admin/coupon/delete");
            perms.add("GET /admin/topic/list");
            perms.add("POST /admin/ad/update");
            perms.add("GET /admin/coupon/read");
            perms.add("POST /admin/topic/update");
            perms.add("POST /admin/groupon/create");
            perms.add("POST /admin/coupon/update");
        //创建这个infobean的过程，应该是大家数据库查询的过程
            infoBean.setRoles(roles);
            infoBean.setPerms(perms);
            return BaseRespVo.ok(infoBean);
        }
    }

    @RequestMapping("logout")
    public BaseRespVo logout() {
        return BaseRespVo.ok();
    }
}
